package com.ly.integral.service.impl;

import com.ly.integral.domain.Integral;
import com.ly.integral.mapper.IntegralMapper;
import com.ly.integral.service.IntegralService;
import com.domain.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class IntegralServiceImpl implements IntegralService {

    @Autowired
    private IntegralMapper integralMapper;



    @Override
    public void insert(Order order) {
        //入库之前先查询，实现幂等
        if (integralMapper.getByOrderNo(String.valueOf(order.getId()))>0){
//            logger.info("积分添加完成，订单已处理。{}",order.getOrderNo());
            System.out.println("积分添加完成，订单已处理。"+order.getId());
        }else{
            Integral integral = new Integral();
            integral.setUserId("1");
            integral.setOrderId(order.getId());
            integral.setVipId("1");
            integral.setIntegral("20");
            integralMapper.insert(integral);
//            logger.info("已为订单号码{}增加积分。",points.getOrderNo());
            System.out.println("已为订单号码{}增加积分。"+order.getId());
        }
    }
}
